{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d5753290-401f-41e6-bc97-5bb2bc726092",
   "metadata": {},
   "source": [
    "# 测试Langchain自定义Tools"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cdabe943-1cae-48b3-8fd4-e1ba5f64ca88",
   "metadata": {},
   "source": [
    "## 1. 基本工具：加法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f3a016f0-1088-413f-b607-4082540b0123",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数 7 与 8 相加的结果是 15。\n"
     ]
    }
   ],
   "source": [
    "from langchain.agents import Tool\n",
    "\n",
    "# 定义加法功能\n",
    "def add_numbers(a, b):\n",
    "    return f\"数 {a} 与 {b} 相加的结果是 {a + b}。\"\n",
    "\n",
    "# 封装为工具Tool\n",
    "addition_tool = Tool(\n",
    "    name=\"加法工具\",\n",
    "    func=lambda query: add_numbers(7, 8),\n",
    "    description=\"一个用于执行加法运算的工具。\"\n",
    ")\n",
    "\n",
    "# 测试调用\n",
    "result = addition_tool.func(query=\"\")\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f9aee9bd-42e5-43fd-9a9c-9fa212a0057c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py3.12_torch22",
   "language": "python",
   "name": "py3.12_torch22"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
